/**
题意：删除链表中等于给定值 val 的所有节点。
示例 1： 输入：head = [1,2,6,3,4,5,6], val = 6 输出：[1,2,3,4,5]
示例 2： 输入：head = [], val = 1 输出：[]
示例 3： 输入：head = [7,7,7,7], val = 7 输出：[]
*/

function removeElement(head, val) {
  while (head !== null && head.val == val) {
    head = head.next;
  }
  if (head === null) {
    return head;
  }
  let pre = head,
    cur = head.next;
  while (cur) {
    if (cur.val == val) {
      pre.next = cur.next;
    } else {
      pre = pre.next;
    }
    cur = cur.next;
  }
  return head;
}
console.log("输入1：", removeElement([1, 2, 6, 3, 4, 5, 6], 6));
